package com.cn.wanxi.servlet;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.service.CompanyService;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.NavService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;

import javax.servlet.http.HttpServletRequest;

class CommonServlet {
    static void setCompanyAndNavData(HttpServletRequest req) {
//        CompanyService companyService = new CompanyService();
//        这种情况，可以理解为为ICompanyService创建了一个匿名内部类
//        lamda表达式
        String path = req.getServletContext().getRealPath("/");
//        截取字符串subString，subStr

        path = path.split("out")[0] + "web";
        ICompanyService iCompanyService = new CompanyServiceImpl();
        CompanyModel companyModel = iCompanyService.getCompanyModel(path);
        req.setAttribute("companyModel", companyModel);

        INavService iNavService = new NavServiceImpl();
//        NavService navService = new NavService();
        NavModel[] navModels = iNavService.getNavModels(path);
        req.setAttribute("navModels", navModels);
    }
}
